package cn.bluethink.eguan.statistics.entity;

import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

import cn.bluethink.eguan.core.entity.EgUserEntity;
import cn.bluethink.eguan.model.core.EgUser;
import cn.bluethink.eguan.model.okrtask.EgOkrTask;
import cn.bluethink.eguan.model.okrtask.EgTarget;

/**
 * @title 目标实体
 * @Copyright 苏州中科蓝迪公司所有(c)2016-2021
 * @version 0.1
 *
 * @note 修订历史： （1）liuxn于2019年1月29日构建初始版本0.1
 */
public class EgTargetEntity implements Serializable {
	private static final long serialVersionUID = -3852235960652649332L;

	/**
	 * 任务ID
	 */
	private Long tid;
	
	// 任务名称
	private String tname;
	
	// 任务完成时间
	private Date ftime;
	
	// 任务截止时间
	private Date etime;
	
	// 任务状态
	private Integer status;
	
	// 目标类型
	private Integer timing;
	
	// 任务参与人列表
	private List<EgUserEntity> userList;
	
	// 所有已完成关键项个数
	private Double completekrs;
	
	// 所有关键项
	private Double krcount;
	
	/**
	 * 前置目标Id
	 */
	private Long parent;
	
	// 前置目标名称
	private String preTargetName;
	
	// 目标颜色
	private Integer color;
	
	// 目标关联的下级子目标
	private List<Long> relateIds;

	public EgTargetEntity() {
		
	}
	
	/**
	 * 转换为工作任务
	 * @param entity
	 * @return
	 */
	public EgTarget createTask() {
		EgTarget target = new EgTarget(tid, tname, null);
		target.setFtime(ftime);
		target.setEtime(etime);
		target.setStatus(status);
		target.setTiming(timing);
		target.setUserList(null);
		// 设置参与人列表
		if(userList != null && userList.size() > 0) {
			List<EgUser> users = userList.stream().map(u -> u.createUser()).collect(Collectors.toList());
			target.setUserList(users);
		}
		if(krcount != null){
			completekrs = completekrs == null ? 0:completekrs;
			// double 精度缺失 限制小数位数为两位，末位舍入
			DecimalFormat decimalFormat = new DecimalFormat("0.00");
			String targetProgress = decimalFormat.format(completekrs/krcount);
			target.setTargetProgress(targetProgress);
		}else{
			target.setTargetProgress("0.0");
		}
		
		
		if(parent != null && parent > 0) {
			target.setParent(new EgOkrTask(parent, preTargetName, null));
		}
		
		if(color == null || color == 0) color = null;
		target.setColor(color);
		return target;
	}

	public Long getTid() {
		return tid;
	}

	public void setTid(Long tid) {
		this.tid = tid;
	}

	public String getTname() {
		return tname;
	}

	public void setTname(String tname) {
		this.tname = tname;
	}

	public Date getFtime() {
		return ftime;
	}

	public void setFtime(Date ftime) {
		this.ftime = ftime;
	}

	public Date getEtime() {
		return etime;
	}

	public void setEtime(Date etime) {
		this.etime = etime;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public Integer getTiming() {
		return timing;
	}

	public void setTiming(Integer timing) {
		this.timing = timing;
	}
	
	public List<EgUserEntity> getUserList() {
		return userList;
	}

	public void setUserList(List<EgUserEntity> userList) {
		this.userList = userList;
	}
 
	public Double getCompletekrs() {
		return completekrs;
	}

	public void setCompletekrs(Double completekrs) {
		this.completekrs = completekrs;
	}

	public Double getKrcount() {
		return krcount;
	}

	public void setKrcount(Double krcount) {
		this.krcount = krcount;
	}

	public Long getParent() {
		return parent;
	}

	public void setParent(Long parent) {
		this.parent = parent;
	}

	public String getPreTargetName() {
		return preTargetName;
	}

	public void setPreTargetName(String preTargetName) {
		this.preTargetName = preTargetName;
	}

	public Integer getColor() {
		return color;
	}

	public void setColor(Integer color) {
		this.color = color;
	}

	public List<Long> getRelateIds() {
		return relateIds;
	}

	public void setRelateIds(List<Long> relateIds) {
		this.relateIds = relateIds;
	}


}
